﻿namespace KinonekoSoftware.Studio.Pages.Others
{
    public sealed class RecycleBinViewModel : RepositoryGalleryItem
    {
        private readonly InstanceCacheEngine _engine;
        private int                 _version;
        
        public RecycleBinViewModel()
        {
            _engine    = Platform.GetEngine<InstanceCacheEngine>();
            RecycleBin = new ObservableCollection<InstanceCache>();
        }

        private void Initialize()
        {
            var deleted = _engine.GetRemovedInstances();
            
            //
            //
            RecycleBin.AddMany(deleted, true);
            _version = _engine.Version;
        }

        protected override void OnStart()
        {
            Initialize();
            base.OnStart();
        }

        protected override void OnResume()
        {
            if (_version != _engine.Version)
            {
                Initialize();
            }
            base.OnResume();
        }

        public ObservableCollection<InstanceCache> RecycleBin { get; }
    }
}